package top.shen33.yang.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletResponse;


@Api
@RestController
@CrossOrigin
public  abstract  class BaseController <T>{


    @ApiOperation(httpMethod = "GET",value = "home页面（暂时不用）",notes = "home")
    @RequestMapping(path = {"/","/home"})
    public Object home(){

        ModelAndView mav=new ModelAndView("/home");
        return mav;
    }

    @ApiOperation(httpMethod = "POST",value = "新增",notes = "add")
    @RequestMapping(value = "/add")
    abstract  public Object doAdd(@RequestBody  T t) throws Exception;


    @ApiOperation(httpMethod = "GET",value = "删除",notes = "delete" ,consumes = "application/x-www-form-urlencoded")
    @RequestMapping(value = "/delete")
    abstract  public Object deDelete(String[] ids) throws Exception;


    @ApiOperation(httpMethod = "POST",value = "修改",notes = "update")
    @RequestMapping("/update")
    abstract  public Object doUpdate(@RequestBody  T t) throws Exception;


    @ApiOperation(httpMethod = "GET",value = "查询单个对象",notes = "get",consumes = "application/x-www-form-urlencoded")
    @RequestMapping("/get/{id}")
    abstract  public Object getOne(@PathVariable("id") String id) throws Exception;

    @ApiOperation(httpMethod = "GET",value = "分页列表",notes = "pageInfo",consumes = "application/x-www-form-urlencoded")
    @RequestMapping("/pageInfo")
    abstract  public Object pageInfo(Page page, T t) throws Exception;

    @ApiOperation(httpMethod = "GET",value = "查询所有（根据条件筛选）",notes = "all",consumes = "application/x-www-form-urlencoded")
    @RequestMapping(value = "/all")
    abstract public Object all(T t) throws Exception;

    @ApiOperation(httpMethod = "GET",value = "excel导出",notes = "export",consumes = "application/x-www-form-urlencoded")
    @RequestMapping("/export")
    public abstract void exportExcel(HttpServletResponse response, T t) throws Exception;

    @ApiOperation(httpMethod = "GET",value = "导入",notes = "import",consumes = "application/x-www-form-urlencoded")
    @RequestMapping("/import")
    public abstract Object importExcel(@RequestParam("file") MultipartFile file) throws Exception;
}
